package com.scsj.supermarket.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scsj.supermarket.R;
import com.scsj.supermarket.utils.Tool;

import java.util.List;

/**
 * 所有商品评价
 */
public class AllGoodsCommentAdapter extends BaseQuickAdapter<String,BaseViewHolder> {
    //加载图片评论布局
    private LinearLayout reputationImgLayout;
    private List data;
    private Context context;
    public AllGoodsCommentAdapter(List data, Context context) {
        super(R.layout.item_all_goods_comment_layout,data);
        this.data=data;
        this.context= context;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        reputationImgLayout= helper.getView(R.id.goods_detail_add_view_tv);
        /**
         * 添加评论图片
         */
        addReputationImg(data);
    }
    private void addReputationImg(List<String> listImg) {
        if (reputationImgLayout.getChildCount()>0){
            reputationImgLayout.removeAllViews();
        }
        for (int i = 0; i < listImg.size(); i++) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_compution_img_layout,null);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    240, 240);
            lp.setMargins(0, 0, Tool.dip2px(context, 10), 10);
            view.setLayoutParams(lp);
            ImageView reputationIv = view.findViewById(R.id.reputation_img);
            Glide
                    .with(context)
                    .load(listImg.get(i))
                    .transform(new Tool.GlideRoundTransform(context,15))
                    .placeholder(R.mipmap.classify_goods_default)
                    .error(R.mipmap.classify_goods_default)
                    .into(reputationIv);

            reputationImgLayout.addView(view);

        }
    }
}
